//
//  DZNEmptyDataSet+Extension.swift
//  gongchengyan
//
//  Created by wang shuguan on 2020/3/18.
//  Copyright © 2020 wsg. All rights reserved.
//

import UIKit
import DZNEmptyDataSet
extension UIViewController:DZNEmptyDataSetSource,DZNEmptyDataSetDelegate {
    func setupEmpty(tableView:inout UITableView,shouldVip:Bool = false) {
        tableView.emptyDataSetDelegate = self
        tableView.emptyDataSetSource = self
        if shouldVip{
            tableView.tag = 1001
        }
    }
    func setupEmpty(collectionView:inout UICollectionView,shouldVip:Bool = false) {
        collectionView.emptyDataSetDelegate = self
        collectionView.emptyDataSetSource = self
        if shouldVip{
            collectionView.tag = 1001
        }
    }
    public func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
        return UIImage(named: "img_remind_icon_01.png")
    }
    public func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
        if !Preference.isVip,scrollView.tag == 1001{
            if (Preference.token ?? "").isEmpty{
                return NSAttributedString(string: "登录后查看更多信息>>",attributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14),NSAttributedString.Key.foregroundColor:UIColor(named: "TextDark1") ?? .default])
            }else{
                return NSAttributedString(string: "开通VIP后查看更多信息>>",attributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14),NSAttributedString.Key.foregroundColor:UIColor(named: "TextDark1") ?? .default])
            }
        }
        return NSAttributedString(string: "暂无数据",attributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14),NSAttributedString.Key.foregroundColor:UIColor(named: "TextDark1") ?? .default])
    }
    
    public func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> NSAttributedString? {
        let attrText = NSMutableAttributedString(string: "如有疑问，请联系客服：",attributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14),NSAttributedString.Key.foregroundColor:UIColor(named: "TextGray1") ?? .default])
        attrText.append(NSAttributedString(string: "400-886-7729",attributes: [NSAttributedString.Key.foregroundColor:UIColor(named: "TextOrange1") ?? .default,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14)]))
        return attrText
    }
    public func emptyDataSet(_ scrollView: UIScrollView, didTap view: UIView) {
        if !Preference.isVip,scrollView.tag == 1001{
            if (Preference.token ?? "").isEmpty{
                NotificationCenter.default.post(name: .userLogout, object: "stay")
            }else{
                self.gotoRenewal()
            }
        }
        scrollView.mj_header?.beginRefreshing()
    }
    public func emptyDataSet(_ scrollView: UIScrollView, didTap button: UIButton) {
        callTel(to: "400-886-7729", name: "客服")
    }
}
